package com.iot.service.mqtt.handler;

import com.iot.service.mqtt.service.session.ISessionService;
import com.iot.service.mqtt.service.subscripe.ISubscriptionService;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @Author: hszhou
 * @Date: 2024/11/25 14:37
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@ChannelHandler.Sharable
@Component
@RequiredArgsConstructor
public class TlMqttExceptionHandler extends ChannelInboundHandlerAdapter {

    private static final  Logger logger = LoggerFactory.getLogger(TlMqttExceptionHandler.class);

    private final ISubscriptionService subscriptionService;

    private final ISessionService sessionService;




    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ReferenceCountUtil.release(cause);
        logger.error("出现异常{}",cause.getCause().getMessage());
        ctx.close();
    }
}
